#include "hzpch.h"
#include "OrthoGraphicCamera.h"

#include <glm/gtc/matrix_transform.hpp>

namespace Hazal
{
    COrthoGraphicCamera::COrthoGraphicCamera(float fleft, float fRight, float fBottom, float fTop)
        :m_projectMatrix(glm::ortho(fleft, fRight, fBottom, fTop, -1.0f, 1.0f)), 
         m_viewMatrix(glm::mat4(1.0f)), m_positionVec(glm::vec3(0.0f)), m_fRotation(0)
    {
        m_viewProjMatrix = m_projectMatrix * m_viewMatrix;
    }
    void COrthoGraphicCamera::SetPosition(const glm::vec3& vecPosition)
    {
        m_positionVec = vecPosition;
        RecalculateMatrix();
    }

    const glm::vec3& COrthoGraphicCamera::GetPosition() const
    {
        return m_positionVec;
    }

    const glm::mat4& COrthoGraphicCamera::GetViewMatrix() const
    {
        return m_viewMatrix;
    }
    
    void COrthoGraphicCamera::SetProjectionMatrix(float fleft, float fRight, float fBottom, float fTop)
    {
        m_projectMatrix = glm::ortho(fleft, fRight, fBottom, fTop, -1.0f, 1.0f);
        m_viewProjMatrix = m_projectMatrix * m_viewMatrix;
    }

    const glm::mat4& COrthoGraphicCamera::GetProjectionMatrix() const
    {
        return m_projectMatrix;
    }

    const glm::mat4& COrthoGraphicCamera::GetViewProjMatrix() const
    {
        return m_viewProjMatrix;
    }

    void COrthoGraphicCamera::SetRotation(float fRotation)
    {
        m_fRotation = fRotation;
        RecalculateMatrix();
    }

    const float COrthoGraphicCamera::GetRotation() const
    {
        return m_fRotation;
    }

    void COrthoGraphicCamera::RecalculateMatrix()
    {
        m_viewMatrix = glm::translate(glm::mat4(1), m_positionVec) *
                            glm::rotate(glm::mat4(1.0f), glm::radians(m_fRotation), glm::vec3(0.0f, 0.0f, 1.0f));
        m_viewMatrix = glm::inverse(m_viewMatrix);

        m_viewProjMatrix = m_projectMatrix * m_viewMatrix;

    }
}